<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="ID" >
        <el-input
          v-model="queryParams.id"
          placeholder="请输入ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:notice:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:notice:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:notice:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="noticeList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection"   fixed="left" width="55" align="center" />
      <el-table-column label="序号" fixed="left" align="center" prop="id" width="100" />
      <el-table-column label="昵称"  fixed="left" align="nickName" prop="sex" width="200" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          {{ getMap(scope.row.status) }}
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center" prop="email" width="100" />

      <el-table-column label="创建者" align="center" prop="createBy" width="100" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:user:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:user:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form v-if="!form.id" ref="form" :model="form" :rules="rules" label-width="180px">
       <el-col :span="24">
  <el-form-item label="account:" prop="account">
    <el-input v-model="form.account" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="free:" prop="free">
    <el-input v-model.number="form.free" placeholder="请输入..." />
  </el-form-item>
</el-col>
<el-col :span="24">
  <el-form-item label="nickname:" prop="nickname">
    <el-input v-model="form.nickname" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="password:" prop="password">
    <el-input v-model="form.password" placeholder="请输入..." />
  </el-form-item>
</el-col>
      </el-form>
      <el-form v-else ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="用户昵称" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请输入..." />
            </el-form-item>
          </el-col>

          <el-col :span="24">
  <el-form-item label="availableUsdtNum:" prop="availableUsdtNum">
    <el-input v-model="form.availableUsdtNum" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="certificationStatus:" prop="certificationStatus">
    <el-input v-model="form.certificationStatus" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="digitalCurrencyAddr:" prop="digitalCurrencyAddr">
    <el-input v-model="form.digitalCurrencyAddr" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="email:" prop="email">
    <el-input v-model="form.email" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="freezeUsdtNum:" prop="freezeUsdtNum">
    <el-input v-model="form.freezeUsdtNum" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="id:" prop="id">
    <el-input v-model="form.id" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="inviteCode:" prop="inviteCode">
    <el-input v-model="form.inviteCode" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="inviteUserId:" prop="inviteUserId">
    <el-input v-model="form.inviteUserId" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="inviteUserPhone:" prop="inviteUserPhone">
    <el-input v-model="form.inviteUserPhone" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="nickName:" prop="nickName">
    <el-input v-model="form.nickName" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="phone:" prop="phone">
    <el-input v-model="form.phone" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="register:" prop="register">
    <el-input v-model="form.register" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="status:" prop="status">
    <el-input v-model="form.status" placeholder="请输入..." />
  </el-form-item>
</el-col><el-col :span="24">
  <el-form-item label="usdtNum:" prop="usdtNum">
    <el-input v-model="form.usdtNum" placeholder="请输入..." />
  </el-form-item>
</el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
var csMap = {
  0: "-",
  1: "已认证",
  2: "待审核",
  3: "未认证",
  4: "审核拒绝",
};
var res;
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        createBy: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [{ required: true, message: "昵称不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getMap(i) {
      return csMap[i] || "";
    },
    /** 查询列表 */
    async getList() {
      this.loading = true;
      res = await this.http("/otc/merchant/merchantList");
      this.noticeList = res.rows;
      this.total = res.total;
      this.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.noticeId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "修改";
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(async (valid) => {
        if (valid) {
          if (this.form.noticeId != undefined) {
            updateNotice(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            res = await this.http.post("/otc/merchant/add",this.form)
            this.message(res)
            this.open = false;
            this.getList();
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.userId || this.ids;
      this.$modal
        .confirm('是否确认删除公告编号为"' + Ids + '"的数据项？')
        .then(function () {
           
          return delUser(Ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
